<?php 

$return = array();
//判断必要参数appid是否存在
$appId = isset($_GET['appId'])?$_GET['appId']:"";
if (empty($appId)) {
	$return['code'] = 10001;
	$return['data'] = 'Lack of necessary parameters';
}else{	
	//本地文档相对路径	
	$url = './images/'; 
	//二维码名称
	$imgName = $appId.'.png';
	//判断二维码是否已经存在
	@$filesize = getimagesize($url.$imgName);
	if ($filesize) {
		$img = 'http://pay.hispot.cn/app/images/'.$imgName; //二维码路径
		$return['code'] = 10000;
		$return['data'] = $img;
	}else{
		//引入php QR库文件
		include_once('./phpqrcode/phpqrcode.php');
		$value = 'http://pay.hispot.cn/app/index.php?appId='.$appId;
		$errorCorrectionLevel = 'H'; //容错级别
		$matrixPointSize = 8; //生成图片大小
		//生成二维码,第二个参数为二维码保存路径
		QRcode::png($value, $url.$imgName, $errorCorrectionLevel, $matrixPointSize, 2);   
	    $logo = './images/logo.png';//准备好的logo图片   
	    $QR = $url.$imgName;//已经生成的原始二维码图   
	        
	    if ($logo !== FALSE) {   
	        $QR = imagecreatefromstring(file_get_contents($QR));   
	        $logo = imagecreatefromstring(file_get_contents($logo));   
	        $QR_width = imagesx($QR);//二维码图片宽度   
	        $QR_height = imagesy($QR);//二维码图片高度   
	        $logo_width = imagesx($logo);//logo图片宽度   
	        $logo_height = imagesy($logo);//logo图片高度   
	        $logo_qr_width = $QR_width / 5;   
	        $scale = $logo_width/$logo_qr_width;   
	        $logo_qr_height = $logo_height/$scale;   
	        $from_width = ($QR_width - $logo_qr_width) / 2;   
	        //重新组合图片并调整大小   
	        imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width,    
	        $logo_qr_height, $logo_width, $logo_height);   
	    }   
	    //输出图片   
	    imagepng($QR, $url.$imgName);
		$img = 'http://pay.hispot.cn/app/images/'.$imgName; //二维码路径
		$return['code'] = 10000;
		$return['data'] = $img;
	}
}
	echo json_encode($return);
 ?>